//
//  FCCBaseViewController.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/4/20.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "FCCBaseViewController.h"

@interface FCCBaseViewController ()<UINavigationControllerDelegate,UIGestureRecognizerDelegate>

@property (nonatomic,strong) UIPercentDrivenInteractiveTransition *interactiveTransition;
 
@end

@implementation FCCBaseViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear: animated];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = UIColor.whiteColor;
    
    [self initTopView];
    
    
    id target = self.navigationController.interactivePopGestureRecognizer.delegate;
    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
    panGesture.delegate = self; // 设置手势代理，拦截手势触发
    [self.view addGestureRecognizer:panGesture];
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

- (void)setTopTitle:(NSString *)topTitle{
    _topTitle = topTitle;
    self.titleLB.text = _topTitle;
}

#pragma mark - UI
-(void)initTopView{
    [self.view addSubview:self.topNavView];
    [self.topNavView addSubview:self.backBtn];
    [self.topNavView addSubview:self.titleLB];
}
#pragma mark - lazy
- (UIView *)topNavView{
    if (!_topNavView) {
        _topNavView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, kHeight_NavBar)];
        _topNavView.backgroundColor = UIColor.whiteColor;
    }
    return _topNavView;
}

-(UIButton *)backBtn{
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _backBtn.frame = CGRectMake(15, kHeight_StatusBar + 5, 35, 35);
        [_backBtn setImage:LoadImage(@"登录注册_back") forState:normal];
        [_backBtn setImageEdgeInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
        [_backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backBtn;
}

- (UILabel *)titleLB{
    if (!_titleLB) {
        _titleLB = [[UILabel alloc] initWithFrame:CGRectMake(60, kHeight_StatusBar+10, ScreenWidth-120, 24)];
        _titleLB.textColor = MainBlackTextColor;
        _titleLB.font = FontSetWithWeight(18, 0.2f);
        _titleLB.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLB;
}

#pragma mark - SEL
-(void)backClick{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - ges
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    // 当当前控制器是根控制器时，不可以侧滑返回，所以不能使其触发手势
    if(self.navigationController.childViewControllers.count == 1){
        return NO;
    }
    return YES;
}



@end
